package com.hxzy.rabbitmqpublisher.controller;

import com.hxzy.common.ExchangeConst;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author wy
 * @Description 路由交换机发消息
 * @Date 2024/2/21 16:10
 * @Version 1.0
 */
@RestController
public class TopicController {

    @Autowired
    private RabbitTemplate  rabbitTemplate;

    // queue01   路由key=orders.#
    //http://localhost:18081/topic/send?msg=abc&key=orders.abc.bbb.ddd

    //http://localhost:18081/topic/send?msg=1234&key=mail.bbb.order
    // queue02    路由key=mail.*.order
    @GetMapping(value = "/topic/send")
    public String sendTopic(String msg,String key){
       this.rabbitTemplate.convertAndSend(ExchangeConst.QUEUE_TOPIC_EXCHANGE,key,msg);
        return "topic发送成功";
    }
}
